const express = require('express');
const cors = require('cors');
const bodyparser = require('body-parser');
const xsrouter = require('./router/xuesheng');
const login = require('./router/login');
const db = require('./db/index');
const router = require('./router/xuesheng');

const app = express();

app.use(express.static('public'));
app.use(cors());
app.use(bodyparser.urlencoded({extended:true}));
app.use('/',async(req,res,next)=>{
    try{
        await db;
        next();
    }catch(e){
        console.log(e);
        res.send('服务器和数据库连接失败')
    }
})
app.use(xsrouter);


app.listen(8000,err=>{
    if(!err){
        console.log('服务器启动成功O(∩_∩)O');
    }
    else{
        console.log(err);
    }
})